<? ob_start(); ?>
<?php
class ReceiptsController extends AppController {

	var $name = 'Receipts';
	//var $uses = array('Receipt', 'Schedule');		//dung nhieu model thi dua vao
	var $helpers = array('Javascript','Ajax');
	var $components = array('RequestHandler');

	
	function upd($id = null) {
		$this->Receipt->delete($id);
		$this->redirect(array('controller'=>'trainees', 'action'=>'step1'));
	}
	function admin_index() {
		$this->Receipt->recursive = 0;
		$this->set('receipts', $this->paginate());
	}

	function admin_view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid receipt', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('receipt', $this->Receipt->read(null, $id));
	}

	function admin_add() {
		if (!empty($this->data)) {
			$this->Receipt->create();
			if ($this->Receipt->save($this->data)) {
				$this->Session->setFlash(__('The receipt has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The receipt could not be saved. Please, try again.', true));
			}
		}
		$trainees = $this->Receipt->Trainee->find('list');
		$payments = $this->Receipt->Payment->find('list');
		$subjects = $this->Receipt->Subject->find('list');
		$testslots = $this->Receipt->Testslot->find('list');
		$this->set(compact('trainees', 'payments', 'subjects', 'testslots'));
	}

	function admin_edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid receipt', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Receipt->save($this->data)) {
				$this->Session->setFlash(__('The receipt has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The receipt could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Receipt->read(null, $id);
		}
		$trainees = $this->Receipt->Trainee->find('list');
		$payments = $this->Receipt->Payment->find('list');
		$subjects = $this->Receipt->Subject->find('list');
		$testslots = $this->Receipt->Testslot->find('list');
		$this->set(compact('trainees', 'payments', 'subjects', 'testslots'));
	}

	function admin_delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for receipt', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Receipt->delete($id)) {
			$this->Session->setFlash(__('Receipt deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Receipt was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>